package com.example.nyf.web;

import com.alibaba.fastjson.JSON;
import com.example.nyf.dto.SysMenuDTO;
import com.example.nyf.entity.SysMenu;
import com.example.nyf.service.SysMenuService;
import com.example.nyf.web.system.BaseController;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
public class IndexController extends BaseController {

    @Autowired
    SysMenuService sysMenuService;

    @RequestMapping("/index")
    public ModelAndView index() {

        List<SysMenuDTO> sysMenuList = sysMenuService.listSysMenu(getSysUser().getId());

        ModelAndView modelAndView =  new ModelAndView("index/index.html");
        modelAndView.addObject("avatar", getSysUser().getAvatar());
        modelAndView.addObject("username", getSysUser().getUser_name());
        modelAndView.addObject("sysMenuList", JSON.toJSONString(sysMenuList));

        return modelAndView;
    }

}
